package com.reef.controller;


import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.reef.entity.Reader;
import com.reef.entity.Result;
import com.reef.service.ReaderService;
@RestController
public class ReaderController {
	@Autowired
	private ReaderService reService;
	/**
	 * 登录
	 */
	@RequestMapping(value = "/findByR_idAndpassword",method = RequestMethod.POST)
	public Object findByR_idAndpassword(int r_id, String password,int staus,HttpSession session) {
		Reader list = reService.findByR_idAndpassword(r_id, password,staus);
		if(list!=null) {
			session.setAttribute("list",list );
			return new Result("登录成功",list,true);
		}else {
			return new Result("登录失败","",false);
		}
	}
	@RequestMapping("/updatePwd")
	public Object updatePwd(String pwd,int id) {
		int i = reService.updatePwd(pwd, id);
		if(i == 0) {
			return new Result("修改失败","",false);
		}else {
			return new Result("修改成功","",true);
		}
	}
	@RequestMapping("/findByid")
	public Object findByid(int r_id) {
		Reader rea = reService.findByR_id(r_id);
		if(rea == null) {
			return new Result("查询失败","",false);
		}else {
			return new Result("查询成功",rea,true);
		}
	}
	@RequestMapping("/updateByBigBook")
	public Object updateByBigBook(int borrowbook, int bigbook, int id) {
		int i = reService.updateByBigBook(borrowbook, bigbook, id);
		if(i == 0) {
			return new Result("修改失败","",false);
		}else {
			return new Result("修改成功",i,true);
		}
	}
	@RequestMapping("/updateByGiveBook")
	public Object updateByGiveBook(int givenbook,int bigbook,int id) {
		int i = reService.updateByGiveBook(givenbook, bigbook, id);
		if(i == 0) {
			return new Result("修改失败","",false);
		}else {
			return new Result("修改成功",i,true);
		}
	}
	
	
	
	
	
}
